﻿<?php
	include "fonctions.php";
	session_start();
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
	<head>
		<meta content="text/html;charset=UTF-8" http-equiv="Content-Type" />
		<link media="all" href="feuille.css" type="text/css" rel="stylesheet" />
		<script type="text/javascript" src = "JavaScript/creer_atelier.js"></script>
		<?php
			if (isset($_POST['nom']) and isset($_POST['type_atelier']) and isset($_POST['prix']) and isset($_POST['prix_val']) and isset($_POST['description']))
			{
				if ($_POST['prix_val'] == "" or $_POST['prix'] == "false")
				{
					$prix = null;
				}
				else
				{
					$prix = intval($_POST['prix_val']);
				}
				
				if ($_POST['description'] == "")
				{
					$description = null;
				}
				else
				{
					$description = addslashes($_POST['description']);
				}
				
				db_connect();
				$req = "INSERT INTO ateliers VALUES ('".$_POST['nom']."','".$prix."','".$description."', null, ".$_POST['type_atelier'].");";
				
				mysql_query($req) or die (mysql_error());
				
				if (isset($_POST['sujetLibre']) && $_POST['sujetLibre'] == "checked")
				{
					$req = "INSERT INTO sujet VALUES (null, 'Libre', '".$_SESSION['idUtil']."', '".$_POST['nom']."');";
					mysql_query($req) or die (mysql_error());
				}
				
				echo '<meta http-equiv="Refresh" content="0;url=\'gestion_atelier.php\'" />';
			}
		?>
		<title>LMLP: création atelier</title>
	</head>
	
	<body>
		<?php en_tete(); ?>
		
		<div id="contenu">
			<?php menu_lateral_droit(); ?>
			
			<div id="texte">
				<?php vousetesici("création atelier"); ?>
				
				<h1>Création d'un atelier</h1>
				<p class = "p_sous_h1"></p>
				<form action="creer_atelier.php" method="post" id="form">
					<label for="nom">Nom : </label>
					<input type="text" name="nom" id="nom" /><br/><br/>
					
					<label for="type_atelier">Type d'atelier : </label>
					<select name="type_atelier" id = "type_atelier"><?php
							db_connect();
							$req = "SELECT * FROM  `types_ateliers`";
							$res = mysql_query($req) or die (mysql_error());
							echo "\n";
							while($data = mysql_fetch_assoc($res))
							{
								echo "\t\t\t\t\t\t";
								echo "<option value = '".$data['idTypeAtelier']."'>".$data['label']."</option>\n";
							}
						?>
					</select><br /><br />
					
					<label>Cet atelier est :</label>
					<input type="radio" id = "gratuit" name="prix" value="false" checked = "checked" />
					<label for="gratuit">gratuit</label>
					<input type="radio" id = "payant" name="prix" value="true" />
					<label for="payant">payant</label><br />
					
					<div id = "bloc_prix">
						<label for="prix_val">Prix : </label>
						<input type="text" id = "prix_val" name="prix_val" /><br/>
					</div>
					<br />
					
					<label for = "description">Description de l'atelier : </label><br/>
					<textarea id = "description" name = "description" rows = "5" cols = "60"></textarea><br />
					
					<input type="checkbox" id="sujetLibre" name="sujetLibre" value = "checked" checked = "checked" />
					<label for = "sujetLibre">Créer un Sujet libre rattaché à cet atelier.</label><br /><br />
					
					<input type="button" id="boutonCreer" value="Créer l'atelier" />
				</form>
			</div>
		</div>
		
		<?php pied_page(); ?>
	</body>
</html>
